/*
 * @Author: cl
 * @Description: 
 * @Date: 2023-05-05 11:28:38
 * @LastEditTime: 2023-05-05 15:11:23
 * @FilePath: \jsnode\nestjs\naota\src\upload\uploadInterceptor.ts
 * @LastEditors: cl
 */
import { NestInterceptor,Injectable, ExecutionContext, CallHandler, Logger} from '@nestjs/common'
import { Request } from 'express';
import { map } from 'rxjs/operators'

interface data<T> {
    data: T
  }
  
@Injectable()
export class UploadInterceptor implements NestInterceptor{

    intercept(context: ExecutionContext, next: CallHandler<any>) {
        console.log('文件拦截器');
        const request = context.switchToHttp().getRequest() as Request
        const startTime = Date.now();

        return next.handle().pipe(
          map((data) => {
            const endTime = Date.now();
            new Logger().log(`TIME:${endTime-startTime}\tURL:${request.path}\tMTEHOD:${request.method}`)
            return {
              data,
            }
          }),
        )
      }

}